<?php

declare (strict_types=1);
namespace App\Model;

/**
 * @property int $id
 * @property string $keyword
 * @property int $search_count
 * @property string $update_time
 */
class SearchHotlist extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'search_hotlist';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'search_count' => 'integer'];


    public static function addHot($keyword){


        $lang = getLang();

        $info = self::where(['keyword'=>$keyword,'lang'=>$lang])->first();
        if (is_null($info)){
            self::insert(['keyword'=>$keyword,'search_count'=>1]);
        }else{
            $info->increment('search_count',1);
        }
        return true;
    }

}
